package src;

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class AndroidApplicationsManager {

	private List applicationsList;
	private List myApplicationsList;
	protected Shell shell;
	private Menu menuBar;
	private MenuItem fileMenuHeader;
	private Menu fileMenu;
	private MenuItem fileNewItem;
	private MenuItem fileOpenItem;
	private MenuItem fileSaveItem;
	private MenuItem fileSaveAsItem;
	private MenuItem fileExitItem;
	private MenuItem helpMenuHeader;
	private Menu helpMenu;
	private MenuItem helpGetHelpOnlineItem;
	private MenuItem helpAvoutItem;
	private MenuItem toolsMenuHeader;
	private Menu toolsMenu;
	private MenuItem toolsDevicesItem;
	private MenuItem toolsPreferencesItem;

	/**
	 * Launch the application
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			AndroidApplicationsManager window = new AndroidApplicationsManager();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window
	 */
	public void open() {
		final Display display = Display.getDefault();
		createContents();
		shell.setMenuBar(menuBar);
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}

	/**
	 * Create contents of the window
	 */
	protected void createContents() {
		shell = new Shell();
		shell.setSize(601, 499);
		shell.setText("Android Application Manager");

		// Images options (T-ish-Brushed-Overlaid)
		Device device = null;
		Image newImage = new Image(device, "./icons/new.png");
		Image openImage = new Image(device, "./icons/open.png");
		Image saveImage = new Image(device, "./icons/save.png");
		Image saveAsImage = new Image(device, "./icons/saveAs.png");
		Image exitImage = new Image(device, "./icons/exit.png");
		Image devicesImage = new Image(device, "./icons/devices.png");
		Image preferencesImage = new Image(device, "./icons/preferences.png");
		Image helpImage = new Image(device, "./icons/help.png");
		Image aboutImage = new Image(device, "./icons/about.png");
		
		// Create the menu bar
		menuBar = new Menu(shell, SWT.BAR);
		
		// Create the file menu
	    fileMenuHeader = new MenuItem(menuBar, SWT.CASCADE);
	    fileMenuHeader.setText("&File");

	    fileMenu = new Menu(shell, SWT.DROP_DOWN);
	    fileMenuHeader.setMenu(fileMenu);
	    
	    fileNewItem = new MenuItem(fileMenu, SWT.PUSH);
	    fileNewItem.setText("&New");
	    fileNewItem.setImage(newImage);

	    new MenuItem(fileMenu, SWT.SEPARATOR);
	    
	    fileOpenItem = new MenuItem(fileMenu, SWT.PUSH);
	    fileOpenItem.setText("&Open");
	    fileOpenItem.setImage(openImage);
	    
	    fileSaveItem = new MenuItem(fileMenu, SWT.PUSH);
	    fileSaveItem.setText("&Save");
	    fileSaveItem.setImage(saveImage);

	    fileSaveAsItem = new MenuItem(fileMenu, SWT.PUSH);
	    fileSaveAsItem.setText("&Save As");
	    fileSaveAsItem.setImage(saveAsImage);

	    new MenuItem(fileMenu, SWT.SEPARATOR);
	    
	    fileExitItem = new MenuItem(fileMenu, SWT.PUSH);
	    fileExitItem.setText("E&xit");
	    fileExitItem.setImage(exitImage);
	    
	    // Create the device menu
	    toolsMenuHeader = new MenuItem(menuBar, SWT.CASCADE);
	    toolsMenuHeader.setText("&Tools");

	    toolsMenu = new Menu(shell, SWT.DROP_DOWN);
	    toolsMenuHeader.setMenu(toolsMenu);

	    toolsDevicesItem = new MenuItem(toolsMenu, SWT.PUSH);
	    toolsDevicesItem.setText("&Devices");
	    toolsDevicesItem.setImage(devicesImage);

	    new MenuItem(toolsMenu, SWT.SEPARATOR);
	    
	    toolsPreferencesItem = new MenuItem(toolsMenu, SWT.PUSH);
	    toolsPreferencesItem.setText("&Preferences");
	    toolsPreferencesItem.setImage(preferencesImage);
	    
	    // Create the help menu
	    helpMenuHeader = new MenuItem(menuBar, SWT.CASCADE);
	    helpMenuHeader.setText("&Help");

	    helpMenu = new Menu(shell, SWT.DROP_DOWN);
	    helpMenuHeader.setMenu(helpMenu);

	    helpGetHelpOnlineItem = new MenuItem(helpMenu, SWT.PUSH);
	    helpGetHelpOnlineItem.setText("&Get Online Help");
	    helpGetHelpOnlineItem.setImage(helpImage);

	    new MenuItem(helpMenu, SWT.SEPARATOR);
	    
	    helpAvoutItem = new MenuItem(helpMenu, SWT.PUSH);
	    helpAvoutItem.setText("&About");
	    helpAvoutItem.setImage(aboutImage);

		// Add components to window
		final List devicesList = new List(shell, SWT.BORDER);
		devicesList.setBounds(15, 33, 167, 115);

		final Label devicesLabel = new Label(shell, SWT.NONE);
		devicesLabel.setText("Devices:");
		devicesLabel.setBounds(15, 10, 75, 17);

		final Group deviceinfoGroup = new Group(shell, SWT.NONE);
		deviceinfoGroup.setText("Device Information");
		deviceinfoGroup.setBounds(15, 161, 167, 152);

		final Label nameLabel = new Label(deviceinfoGroup, SWT.NONE);
		nameLabel.setText("Name:");
		nameLabel.setBounds(10, 31, 81, 17);

		final Label nameChangeLabel = new Label(deviceinfoGroup, SWT.NONE);
		nameChangeLabel.setText("...");
		nameChangeLabel.setBounds(97, 31, 60, 17);

		final Label diskCapacityLabel = new Label(deviceinfoGroup, SWT.NONE);
		diskCapacityLabel.setText("Capacity:");
		diskCapacityLabel.setBounds(10, 60, 81, 17);

		final Label capacityChangeLabel = new Label(deviceinfoGroup, SWT.NONE);
		capacityChangeLabel.setText("...");
		capacityChangeLabel.setBounds(97, 60, 60, 17);

		final Label freeSpaceLabel = new Label(deviceinfoGroup, SWT.NONE);
		freeSpaceLabel.setText("Free space:");
		freeSpaceLabel.setBounds(10, 90, 73, 17);

		final Label freeSpaceChangeLabel = new Label(deviceinfoGroup, SWT.NONE);
		freeSpaceChangeLabel.setText("...");
		freeSpaceChangeLabel.setBounds(97, 90, 60, 17);

		final Group deviceApplicationsGroup = new Group(shell, SWT.NONE);
		deviceApplicationsGroup.setText("Device Applications");
		deviceApplicationsGroup.setBounds(209, 10, 354, 205);

		applicationsList = new List(deviceApplicationsGroup, SWT.BORDER);
		applicationsList.setBounds(10, 25, 334, 135);

		final Button uninstallButton = new Button(deviceApplicationsGroup, SWT.NONE);
		uninstallButton.setText("Uninstall");
		uninstallButton.setBounds(258, 166, 86, 29);

		final Button uninstallAllButton = new Button(deviceApplicationsGroup, SWT.NONE);
		uninstallAllButton.setText("Uninstall All");
		uninstallAllButton.setBounds(164, 166, 92, 29);

		final Group myApplicationsGroup = new Group(shell, SWT.NONE);
		myApplicationsGroup.setText("My Applications");
		myApplicationsGroup.setBounds(209, 221,354, 205);

		myApplicationsList = new List(myApplicationsGroup, SWT.BORDER);
		myApplicationsList.setBounds(10, 25, 334, 135);

		final Button installButton = new Button(myApplicationsGroup, SWT.NONE);
		installButton.setText("Install");
		installButton.setBounds(258, 166, 86, 29);

		final Button installAllButtons = new Button(myApplicationsGroup, SWT.NONE);
		installAllButtons.setText("Install All");
		installAllButtons.setBounds(164, 166, 92, 29);

		final Button romeveButton = new Button(myApplicationsGroup, SWT.NONE);
		romeveButton.setBounds(10, 166,152, 29);
		romeveButton.setText("Remove Application");

		final Button addApplicationButton = new Button(shell, SWT.NONE);
		addApplicationButton.setBounds(15, 319,150, 30);
		addApplicationButton.setText("Add Application");

		final Button loadBackupButton = new Button(shell, SWT.NONE);
		loadBackupButton.setBounds(15, 355,150, 30);
		loadBackupButton.setText("Load Backup");

		final Button applyButton = new Button(shell, SWT.NONE);
		applyButton.setText("Apply Changes");
		applyButton.setBounds(15, 400, 150, 29);

		final Label label = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
		label.setBounds(20, 385, 150, 17);

	}

}
